package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bo.gh.*;
import com.kuang.demo.dto.BrandDTO;
import com.kuang.demo.pojo.CategoryVO;
import com.kuang.demo.service.CategoryService;
import com.kuang.demo.service.StoreService;
import com.kuang.demo.vo.QueryBrandVO;
import com.kuang.demo.vo.QueryCategoryL1VO;
import com.kuang.demo.vo.QueryCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/10/31 15:54
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @GetMapping("list")
    public BaseRespVo categoryList(){
        List<QueryCategoryVO.DataBean> dataBeanList = categoryService.queryList();
        BaseRespVo ok = BaseRespVo.ok(dataBeanList);
        return ok;
    }
    @GetMapping("l1")
    public BaseRespVo categoryL1List(){
        List<QueryCategoryL1VO.DataBean> dataBeanList = categoryService.queryL1List();
        return BaseRespVo.ok(dataBeanList);
    }

    @PostMapping("create")
    public BaseRespVo createCategory(@RequestBody CreateCategoryBO createCategoryBO){
        CategoryVO category = categoryService.createCategory(createCategoryBO);
        return BaseRespVo.ok(category);
    }

    @PostMapping("update")
    public BaseRespVo updateCategory(@RequestBody UpdateCategoryBO updateCategoryBO){
        categoryService.updateCategoey(updateCategoryBO);
        return BaseRespVo.ok();
    }
    @PostMapping("delete")
    //因为前端更新删除传过来的对象属性一样，复用一哈

    public BaseRespVo deleteCategory(@RequestBody DeleteCategoryBO deleteCategoryBO){
        categoryService.deleteCategory(deleteCategoryBO);
        System.out.println(deleteCategoryBO);
        return BaseRespVo.ok();
    }


}
